/**
 * MemberBillDetailActivity.java
 * com.jamin.aabill.ui
 *
 * Function： TODO 
 *
 *   ver     date      		author
 * ──────────────────────────────────
 *   		 2012-9-6 		wangjieming
 *
 * Copyright (c) 2012, TNT All Rights Reserved.
 */

package com.jamin.aabill.ui;

import java.util.List;

import com.jamin.aabill.R;
import com.jamin.aabill.custom.TopBar;
import com.jamin.aabill.custom.TopBarClickListener;
import com.jamin.aabill.data.BillViewDetail;
import com.jamin.aabill.utils.TimeUtils;
import com.jamin.aabill.utils.Utils;
import com.umeng.analytics.MobclickAgent;

import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.Window;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

/**
 * ClassName:MemberBillDetailActivity
 *
 * @author   wangjieming
 * @version  1.0
 * @since    v1.0
 * @Date	 2012-9-6 下午2:00:59 
 */
public class MemberBillDetailActivity extends Activity{

	private static final String TAG = "MemberBillDetailActivity ======= wangjieming";

	TopBar mTopBar = null;
	TableLayout mItemLayout = null;
	TextView mTotalCostTV = null;

	List<BillViewDetail> mBillViewDetailList = null;
	long circleMemberId = -1;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.member_bill_detail_activity);
		circleMemberId = getIntent().getLongExtra("circleMemberId", -1);
		Utils.log( TAG , "circleMemberId" + circleMemberId);
		mBillViewDetailList = AABillApplication.mBillManager.getBillViewDetailForMember(circleMemberId);
		initView();
		bindView();
	}


	private void initView() {
		mTopBar = (TopBar) findViewById(R.id.top_bar);
		if(mBillViewDetailList.size() > 0){
			mTopBar.setTitle(AABillApplication.mApplicationContext.getString(
					R.string.member_bill_detail_activity_title_with_name,mBillViewDetailList.get(0).getCIRCLE_MEMBER_NAME()));
		}
		mTopBar.setTopBarClickListener(new TopBarClickListener() {
			@Override
			public void rightBtnClick() {
			}
			@Override
			public void right2BtnClick() {
			}
			@Override
			public void leftBtnClick() {
				finish();
			}
		});
		mItemLayout = (TableLayout) findViewById(R.id.member_bill_detail_layout);
		mTotalCostTV = (TextView) findViewById(R.id.member_bill_detail_total_cost);
		mTotalCostTV.setText(AABillApplication.mApplicationContext.getString(
				R.string.member_bill_detail_activity_total_cost, 
				AABillApplication.mBillManager.getMemberTotalCost(circleMemberId)));
	}


	private void bindView() {
		mItemLayout.setStretchAllColumns(true);
		mItemLayout.setShrinkAllColumns(true);
		String Time = AABillApplication.mApplicationContext.getString(R.string.member_bill_detail_activity_bill_time);
		String ProjectTitle = AABillApplication.mApplicationContext.getString(R.string.member_bill_detail_activity_bill_project);
		String CostTitle = AABillApplication.mApplicationContext.getString(R.string.member_bill_detail_activity_bill_cost);
		mItemLayout.addView(getTableRow( Time , ProjectTitle , CostTitle ));
		for(int i = 0 ; i < mBillViewDetailList.size(); i++){
			mItemLayout.addView(getTableRow(
					TimeUtils.FormatTimeForm(mBillViewDetailList.get(i).getCREATE_AT() , "MM-dd"),
					mBillViewDetailList.get(i).getPROJECT(), 
					String.valueOf(mBillViewDetailList.get(i).getMONEY())));
		}
	}


	private TableRow getTableRow(String time , String project , String cost){
		TableRow row = new TableRow(this);
		row.addView(getTextView(time));
		row.addView(getTextView(project));
		row.addView(getTextView(cost));
		return row;
	}


	private TextView getTextView(String name){
		TextView tv = new TextView(this);
		tv.setTextColor(R.color.blue);
		tv.setText(name);
		tv.setBackgroundResource(R.color.item_bg);
		tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
		tv.setGravity(Gravity.CENTER);
		tv.setTypeface(Typeface.SERIF, Typeface.BOLD);
		return tv;
	}



	@Override
	protected void onResume() {
		super.onResume();
		MobclickAgent.onResume(this);

	}

	@Override
	protected void onPause() {
		super.onPause();
		MobclickAgent.onPause(this);
	}







}

